djinnifandomcom-20200222-history
Basics of scripting
Category:Scripts Scripting Practices This document will detail a few basic scripts you can add to modules, and what they do. It also details locations to find many of the function names and constants. When it comes to using the scripting interface, most function and constants are very simple to learn, and are detailed sufficiently. Most functions begin with "Get", "Add", "Set", "Create", "Delete", and "Assign" and you will get a list of every function. As you scroll through, each will be detailed in terms of what they do, and what needs to be passed into the function. I.E. an AddAbility function requires the tag of the ability you wish to add, followed by who it is being added to. All tags can easily be found throughout Djinni. I.E. if you wish to find a tag for a sword, you can either open a pre-designed template and copy the tag, or create a new one and use a new tag. Now when it comes to #defines and constants, you will need to download the NWScriptDefn file at http://www.witchermod.com/djinni/nwscriptdefn.nss (or it can be found in C:\Program Files\The Witcher\System\Scripts) and open in a text editor. In this document will be listed every single constant used (such as equipment slots like INVENTORY_SLOT_STEELSWORD and INVENTORY_SLOT_SHORT1), and every function in The Witcher. It is a very useful reference guide when you are trying to script. Below is an example initialize script with comments to describe what they do. It can be used in "On Client Enter" in Module Properties: void main() { // This initializes Geralt's object to be used in any future scripts. This must be called prior to any script that changes Geralt's actions, abilities, equipment, and inventory. Typically, most Get commands will return an object, so this can also hold true for GetObjectByTag which would return an item for example. object oPC = GetFirstPC(); // The following two commands will erase Geralt's initial equipment and allow you to add whatever equipment you like in later steps. This is necessary as you cannot overwrite an equipment slot until it's empty. This is using default templates. DestroyObject(GetItemPossessedBy(oPC, "it_witcharm_001")); DestroyObject(GetItemPossessedBy(oPC, "it_stlswd_001")); // Creates new armor (Raven's Armor) on Geralt using default template. CreateItemOnObject("it_witcharm_004", oPC, 1); // Since there are two slots a steel sword can go to (INVENTORY_SLOT_STEELSWORD or INVENTORY_SLOT_BIGWEAPON) you need to create an object of the sword. Once it's created, you can then assign it to a certain slot. object steelsword = CreateItemOnObject("it_stlswd_012", oPC, 1); // Creates new silver sword (Moonblade) on Geralt using default template. CreateItemOnObject("it_svswd_006", oPC, 1); // Assigns the steelsword from earlier to the Steel Sword slot on equipment. AssignCommand(oPC, ActionEquipItem(steelsword, INVENTORY_SLOT_STEELSWORD)); // Sets Geralt's initial Toxicity capacity. This can be adjusted, which makes potions more (>100) or less (<100) lethal when drunk. SetCurrentToxinCapacity(100, oPC); // Sets initial starting abilities for Geralt on load. All are required, and there are many others you can set in constants file. AddAbility("HeroStartingAbility", oPC); AddAbility("AutoJump", oPC); AddAbility("AttackFromBehind", oPC); AddAbility("SkinningKnife", oPC); AddAbility("Aard1", oPC); AddAbility("Igni1", oPC); AddAbility("Yrden1", oPC); AddAbility("Axi1", oPC); AddAbility("Quen1", oPC); AddAbility("Dexterity1 Upgrade1", oPC); AddAbility("Intelligence1 Upgrade1", oPC); // Sets the initial experience points for Geralt. This can be any number, and initially sets Geralt's title (I.E. Skilled Witcher) SetXP(oPC, 250000); // Adds talent points to Geralt (Bronze, Silver, Gold). These can be used upon first use of a campfire in the module. AddTalents(40,40,40); }